package spring.factory;

import spring.exceptions.XmlConfigParseErrorException;
import spring.resources.ClassPathXmlReader;
import utils.LogUtils;

public class WebApplicationBeanFactory extends DefaultListableBeanFactory implements WebInitBeanFactory {

    private final ClassPathXmlReader reader;

    public WebApplicationBeanFactory() {
        reader = new ClassPathXmlReader(this);
    }

    @Override
    public void parseXml(String[] configLocations) {
        try {
            for (String configLocation : configLocations) {
                reader.read(configLocation);
            }
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.error("配置文件加载失败，请确认配置的路径有效。");
            throw new XmlConfigParseErrorException(e);
        }
    }

}
